import TileLayer from 'ol/layer/Tile'
// @ts-ignore
import mapTypeList from '@/utils/ol/maptype'
import { Map, View, Feature } from 'ol'
// 地图
const localMap = 'localMap'

export function getMap() {
  // @ts-ignore
  return localStorage.getItem(localMap)
}

export function setMap(e: string) {
  // @ts-ignore
  return localStorage.setItem(localMap, e)
}

// 语言
// const locale = 'locale'

// export function getLan() {
// 	return localStorage.getItem(locale)
// }

// export function setLan(e) {
// 	return localStorage.setItem(locale, e)
// }

function createLayers(mapType: any, t: any) {
  let mt = mapType.find((e: any) => e.id === t)
  if (mt) {
    let vs = mt.value as any
    return vs.map((ele: any, index: number) => {
      return new TileLayer({
        // title: '图层' + index,
        source: ele
      })
    })
  }
  return null
}
export function createLayers2() {
  let localMap = getMap() || '0' // type
  return createLayers(mapTypeList, localMap)
}
export function createMap(target: any, layers: any, center: number[] = [117.12196300000005, 36.66290200000001]) {
  return new Map({
    // 对应元素ID
    target: target,
    layers: layers,
    view: new View({
      // 坐标系，有EPSG:4326和EPSG:3857
      projection: 'EPSG:4326',
      center: center,
      minZoom: 5, // 地图缩放最小级别
      maxZoom: 30,
      zoom: 10 // 设置初始缩放级别
    }),
    controls: []
  })
}
